package easy;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Solution_690 {

    public int getImportance(List<Employee> employees, int id) {
        int[] indexes = new int[2001];
        for (int i = 0; i < employees.size(); i++) {
            indexes[employees.get(i).id] = i;
        }
        int sum = 0;
        Stack<Integer> stack = new Stack<>();
        stack.add(id);
        while (!stack.empty()) {
            Integer tempId = stack.pop();
            Employee employee = employees.get(indexes[tempId]);
            sum += employee.importance;
            if (employee.subordinates != null && employee.subordinates.size() > 0) {
                for (Integer subordinate : employee.subordinates) {
                    stack.push(subordinate);
                }
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        Solution_690 model = new Solution_690();
        List<Employee> list = new ArrayList<>();
        System.out.println(model.getImportance(list, 1));
    }

    static class Employee {
        public int id;
        public int importance;
        public List<Integer> subordinates;
    }

    ;
}
